package com.skt.common_hr.common.approval
{
	//import com.skt.common_hr.biztrip.model.DailyApprovalProxy;
	//import com.skt.common_hr.biztrip_sac.model.DomesticApprovalProxy;
	import com.skt.common_hr.common.Variables;
	import com.skt.common_hr.common.components.CommonAlert;
	import com.skt.common_hr.common.memberselector.MemberSelectorMediator;
	import com.skt.common_hr.common.memberselector.MemberVO;
	import com.skt.common_hr.common.puremvc.CommonMediator;
	import com.skt.common_hr.work_nos.model.WorkTimeApprovalProxy;
	import com.skt.common_hr.work_sac.model.VacationApprovalProxy;
	import com.wcl.utils.StringUtil;
	
	import flash.display.DisplayObject;
	import flash.events.Event;
	import flash.external.ExternalInterface;
	import flash.net.URLRequest;
	import flash.net.URLRequestMethod;
	import flash.net.URLVariables;
	import flash.net.navigateToURL;
	import flash.utils.getQualifiedClassName;
	
	import mx.collections.ArrayCollection;
	import mx.controls.Alert;
	import mx.core.UIComponent;
	import mx.events.CloseEvent;
	import mx.managers.PopUpManager;
	
	import org.puremvc.as3.multicore.interfaces.INotification;

	public class RequestApprovalMediator extends CommonMediator
	{
		public static const NAME:String = "RequestApprovalMediator"; 
		
		public static const APPROVAL_COMPLETE:String 	= "approvalComplete";
		public static const APPROVAL_CANCEL:String		= "approvalCancel";
		
		private var reqProxy:IRequestApprovalProxy;
		private var _appCode:String;
		private var lineList:ArrayCollection = new ArrayCollection;
		
		/**
		* 생성자
		* 
		* @param
		* @return void
		*/
		public function RequestApprovalMediator(pview:UIComponent, appCode:String)
        {
            super( NAME, null );
            _appCode = appCode;
        }
		
			
		private function registerProxies():void
		{
			var lineProxy:ApprovalLineProxy = facade.retrieveProxy(ApprovalLineProxy.NAME) as ApprovalLineProxy;
			if(lineProxy == null) {
				lineProxy = new ApprovalLineProxy();
				facade.registerProxy(lineProxy);
			}
			
			var className:String = getQualifiedClassName(reqProxy);
			var sIdx:int = className.indexOf(":");
			className = className.substring(sIdx+2, className.length);
			 
			if(className == 'WorkTimeApprovalProxy' && Variables.company =='NOS') {
				
				if(	WorkTimeApprovalProxy(reqProxy).dataProvider[0].AWART == '2010' || 
					WorkTimeApprovalProxy(reqProxy).dataProvider[0].AWART == '2011' || 
					WorkTimeApprovalProxy(reqProxy).dataProvider[0].AWART == '2012' ) {
						lineProxy.loadApprovalLine_preOrder(Variables.myPernr, _appCode,
							WorkTimeApprovalProxy(reqProxy).dataProvider[0]
						);						
				} else { 
					lineProxy.loadApprovalLine(Variables.myPernr, _appCode);
				}
			}
			//선우과장 2014.1.22
			else if(className == 'VacationApprovalProxy' && Variables.company =='SAC') {
				var sAwart:String = VacationApprovalProxy(reqProxy).dataProvider[0].AWART;
				lineProxy.loadApprovalLine(Variables.myPernr, _appCode, reqProxy.key, sAwart);
			}
			else {
				lineProxy.loadApprovalLine(Variables.myPernr, _appCode, reqProxy.key);	
			}
			
			//lineProxy.loadApprovalLine(Variables.myPernr, _appCode);
			
			var proxy:ApprovalProxy = facade.retrieveProxy(ApprovalProxy.NAME) as ApprovalProxy;
			if(proxy == null) { 
				proxy = new ApprovalProxy();
				facade.registerProxy(proxy);
			}
		}
		
		public function execRequest(parent:DisplayObject, proxy:IRequestApprovalProxy, bTRPAYC:Boolean = false):void
		{
			reqProxy = proxy;
            registerProxies();
			_appCode = reqProxy.appCode;
			
			if(view==null) {
				createPopUp(parent.root);
			}	
			else {
				PopUpManager.addPopUp(view, parent.root,true);
			}
			view.setFocus(); 
			view.buttonBox.selectedIndex = 0;		
			bActivated = true;
			setEventListener();
			view.approvalTitle = reqProxy.title;
			view.content = reqProxy.content;
			view.fileName = "";
			view.htmlArea.visible = true;

			// 출장일경우에는.. 추가버튼 생김
			var className:String = getQualifiedClassName(reqProxy);
			var sIdx:int = className.indexOf(":");
			className = className.substring(sIdx+2, className.length);
			
			if(Variables.company == 'SAC') {
				if(className == "DomesticApprovalProxy" || className == "ForeignApprovalProxy") {  // 시외 출장
					view.useEacount = true;
					view.bTRPAYC = bTRPAYC; 
				}
				else if(className == "DailyApprovalProxy") { // 시내 출장
					view.useEacount = true;
					view.bTRPAYC = true;				
				} 
				else {
					view.useEacount = false;
					view.bTRPAYC = false;
				}				
			}
			/* 
			else if(Variables.company == 'STC') {				
				if(className == "DomesticApprovalProxy") {  // 시외 출장
					view.useEacount = true;
					view.bTRPAYC = bTRPAYC; 
				}
				else if(className == "DailyApprovalProxy") { // 시내 출장
					view.useEacount = true;
					view.bTRPAYC = true;				
				}
				else if(className == "ForeignApprovalProxy") { // 국외 출장
					view.useEacount = true;
					view.bTRPAYC = bTRPAYC;				
				} 				 
				
				else {
					view.useEacount = false;
					view.bTRPAYC = false;
				}				
			} else if(Variables.company == 'NOS') {				
				if(className == "DomesticApprovalProxy") {  // 시외 출장
					view.useEacount = true;
					view.bTRPAYC = bTRPAYC; 
				}				
				else if(className == "ForeignApprovalProxy") { // 국외 출장
					view.useEacount = true;
					view.bTRPAYC = bTRPAYC;				
				} 				 
				
				else {
					view.useEacount = false;
					view.bTRPAYC = false;
				}				
			}	
			 */				
			clearAppLine(); 
			//setApprovalLines();
		}
		
		public function execView(parent:DisplayObject, proxy:IRequestApprovalProxy=null):void
		{
			//reqProxy = proxy;
           // registerProxies();
			
			if(view==null) {
				createPopUp(parent.root);
			}	
			else {
				PopUpManager.addPopUp(view,parent.root,true);
			}		
			view.buttonBox.selectedIndex = 2;
			bActivated = true;
			setEventListener();
			//view.approvalTitle = reqProxy.title;
			//view.content = reqProxy.content;
			//view.htmlArea.visible = true;
			//setApprovalLines();
		}
		
		private function setApprovalLines():void
		{
			for each(var line:ApprovalLineVO in lineList)
			{
				setAppLine(line.clone());
			} 
		}
		
		///////////////////////////////////////////////////////////////////////////////////////////////////
		//
		//	Process MVC Messages
		//
		///////////////////////////////////////////////////////////////////////////////////////////////////
		/**
		* 본 Class에서 처리해야할 Noti들을 등록한다.
		* 
		* @param
		* @return void
		*/
		override public function listNotificationInterests():Array 
		{
			return[
					ApprovalProxy.SAVE_APPROVAL_COMPLETE,
					ApprovalProxy.SAVE_APPROVAL_FAILED,
					ApprovalLineProxy.LOAD_APPROVAL_LINE_COMPLETE,
					ApprovalLineProxy.LOAD_APPROVAL_LINE_FAILED,
					MemberSelectorMediator.SELECTED_MEMBER,
					MemberSelectorMediator.CANCEL_SELECTION,
					AttachFileProxy.SELECTED_FILE,
					AttachFileProxy.COMPLETE_UPLOAD,
					AttachFileProxy.FAILED_UPLOAD,
					AppLineMediator.CLOSED_APPROVAL_LINE_VIEW,
					AppLineMediator.CANCEL_APPROVAL_LINE_VIEW
					];
		}
		
		

		/**
		* Noti별로 처리한다.
		* 
		* @param
		* @return void
		*/
		override public function handleNotification(note:INotification):void
		{
			if(bActivated) {
				switch(note.getName()) 
				{
					case ApprovalLineProxy.LOAD_APPROVAL_LINE_COMPLETE:
						lineList = (ApprovalLineProxy(note.getBody())).lineList;
						view.bLineEditable = (ApprovalLineProxy(note.getBody())).bEditable;
						setApprovalLines(); 
						break; 		
					case ApprovalLineProxy.LOAD_APPROVAL_LINE_FAILED:
						trace("결재선 정보를 가져오는데 실패했습니다.");
						break; 	
					case ApprovalProxy.SAVE_APPROVAL_COMPLETE:
						trace("결재 요청에 성공했습니다.");
						onSucceedApproval();
						break;
					case ApprovalProxy.SAVE_APPROVAL_FAILED:
						trace(ApprovalProxy(note.getBody()).faultDetail);
						trace("결재 요청에 실패했습니다.");
						break;	
					case MemberSelectorMediator.SELECTED_MEMBER:
						changeAppLine(MemberSelectorMediator(note.getBody()).selectedMember);
						view.htmlArea.visible = true;
						break;
					case MemberSelectorMediator.CANCEL_SELECTION:
						view.htmlArea.visible = true;
						break;
					case AttachFileProxy.SELECTED_FILE:
						onSelectedFile(AttachFileProxy(note.getBody()));
						break;
					case AttachFileProxy.COMPLETE_UPLOAD:
						saveApproval();
						break;
					case AttachFileProxy.FAILED_UPLOAD:
						CommonAlert.showMessage("CommonHR", "ALERT_FAILED_UPLOAD_FILE", null, "ALERT_TITLE_ERROR");
						break;
					case AppLineMediator.CLOSED_APPROVAL_LINE_VIEW:
						if(bActivated) {
							//main.setStatus("결재선이 변경되었습니다.");
							view.htmlArea.visible = true;
							setAppLineList((note.getBody() as AppLineMediator).resultList);
						}
						break;
					case AppLineMediator.CANCEL_APPROVAL_LINE_VIEW:
						if(bActivated) {
							//main.setStatus("결재선이 변경이 취소되었습니다.");
							view.htmlArea.visible = true;
						}
					break;
					default:
						//trace(this.instanceID+"에서 처리 안된 Noti가 검출됨 : " + note.getBody());
						break;
				}
			}
		}
		
		private function changeAppLine(selVO:MemberVO):void
		{
			var line:ApprovalLineVO = new ApprovalLineVO;
			line.GWARELEV = view.selectedLevel;
			line.ENAME = selVO.ENAME;
			line.WPERNR = selVO.PERNR;
			line.ORGTX = selVO.ORGEH;
			setAppLine(line);
		}
		
		private function createPopUp(parent:DisplayObject):void
		{
			viewComponent = PopUpManager.createPopUp(parent, RequestApproval, true);
			PopUpManager.centerPopUp(view);
			view.setFocus();
		}
		
		private function cancelApproval(event:Event):void 
		{
			sEacc = ExternalInterface.call("getEacc");
			if(Variables.company == 'SAC' && sEacc == 'X') {			
				var alt:Alert = Alert.show('결재요청이 완료되지 않았습니다.\r정말로 취소하시겠습니까?', "", 3, view, cancelApprovalHandeler)
				alt.validateNow();  
				alt.move(alt.x, 150);				
				return;
			} 
			
			sEacc = ''; // 증빙 첨부 초기화.
			sFormAttach = ''; 
			var sEaccInit:String = ExternalInterface.call("initEacc");			
			var sFormAttachInit:String = ExternalInterface.call("initFormAttach");
			closeModule();
			facade.sendNotification(APPROVAL_CANCEL, this);
		}
		
		public function cancelApprovalHandeler(e:CloseEvent):void {
			if (e.detail==Alert.YES) {
				sEacc = ''; // 증빙 첨부 초기화. 
				var sEaccInit:String = ExternalInterface.call("initEacc");
			
				sFormAttach = '';				
				var sFormAttachInit:String = ExternalInterface.call("initFormAttach");			
				
				closeModule();
				facade.sendNotification(APPROVAL_CANCEL, this);
   			} else {
				trace('no');
   			}
                    
			
		}
		
		private function onSucceedApproval():void
		{
			closeModule();
			facade.sendNotification(APPROVAL_COMPLETE, this);
		}
		
		private function closeModule():void
		{
			removeEventListener();
			view.closeView();
			bActivated = false;
		}
		
		private function setEventListener():void
		{
			view.addEventListener(RequestApproval.REQUEST_APPROVAL, requestApproval);
			view.addEventListener(RequestApproval.CLOSE_MODULE, cancelApproval);
			view.addEventListener(RequestApproval.PRINT_APPROVAL, printApproval);
			view.addEventListener(RequestApproval.CHANGE_APPLINE, onChangeAppLine);
			view.addEventListener(RequestApproval.ADD_ATTACH_FILE, onAddAttachFile);
			view.addEventListener(RequestApproval.DEL_ATTACH_FILE, onDelAttachFile);
			
			view.addEventListener(RequestApproval.EACNT_APPROVAL, eacntApproval);
			
			//1109
			view.addEventListener(RequestApproval.PRINT_APPROVAL_SEND, printApprovalSend);
			
		}
		
		private function removeEventListener():void
		{
			view.removeEventListener(RequestApproval.REQUEST_APPROVAL, requestApproval);
			view.removeEventListener(RequestApproval.CLOSE_MODULE, cancelApproval);
			view.removeEventListener(RequestApproval.CHANGE_APPLINE, onChangeAppLine);
			view.removeEventListener(RequestApproval.PRINT_APPROVAL, printApproval);
			view.removeEventListener(RequestApproval.ADD_ATTACH_FILE, onAddAttachFile);
			view.removeEventListener(RequestApproval.DEL_ATTACH_FILE, onDelAttachFile);
			
			view.removeEventListener(RequestApproval.EACNT_APPROVAL, eacntApproval);
		}		
		
		public var sEacc:String = '';
		public var sFormAttach:String = '';
		
		private function requestApproval(e:Event):void
		{
			var className:String = getQualifiedClassName(reqProxy);
			var sIdx:int = className.indexOf(":");
			className = className.substring(sIdx+2, className.length);
			
			// 6월 이후부터만 체크함
			var dNow1:Date = new Date(); 
			var dNow2:Date = new Date();
			dNow1.setFullYear(2011, 5, 1); // 6월 1일. 
			
			if(Variables.company == 'SAC') {
				sEacc 		= ExternalInterface.call("getEacc");
			}
									
			/* 
			//20111128 .. 
			
			if(Variables.company == 'SAC') {
				
				sFormAttach = ExternalInterface.call("getFormAttach");
				sEacc 		= ExternalInterface.call("getEacc");
									
				if(className == 'DomesticApprovalProxy' || 'ForeignApprovalProxy' ) { // 시외출장
					
					// 증빙 첨부					
					if(sEacc != 'X' && view.bTRPAYC == true) {
						var alt:Alert = Alert.show('증빙을 첨부하셔야 합니다.');
						alt.validateNow(); 
						alt.move(alt.x, 150);	
						return;
					}			
				}
				else if(className == "DailyApprovalProxy" ) { //시내출장은 무조건 증빙 확인
					if(sEacc != 'X') {
						var alt:Alert = Alert.show('증빙을 첨부하셔야 합니다.');
						alt.validateNow(); 
						alt.move(alt.x, 150);	
						return;
					}				
				}
			}
			 */
			if(view.fileName!="") { 
				var proxy:AttachFileProxy = getFileProxy();
				proxy.uploadFile();
			}
			else {
				saveApproval();
			}
		}
		
		private function saveApproval():void
		{
			if(StringUtil.NVL(view.responsible.WPERNR) != "") {
				var proxy:ApprovalProxy = facade.retrieveProxy(ApprovalProxy.NAME) as ApprovalProxy;
				var lineProxy:ApprovalLineProxy = facade.retrieveProxy(ApprovalLineProxy.NAME) as ApprovalLineProxy;
				var fileProxy:AttachFileProxy = getFileProxy();
				
				var fileInfo:Array = new Array();
				if(view.fileName!="") {
					fileInfo.push({SEQNO:"0", FILE_SIZE:fileProxy.fileSize.toString(), FILE_NAME:fileProxy.fileName, FILE_EXT:fileProxy.fileExt, FILE_URL:fileProxy.fileURL});
				}
				proxy.requestApproval(_appCode, reqProxy.key, reqProxy.title, reqProxy.content, extraInfo(),
										getApprovalLines(), fileInfo, sEacc);
				// 증빙 초기화..
				sEacc = '';						
				var sEaccInit:String = ExternalInterface.call("initEacc");
				sFormAttach = '';				
				var sFormAttachInit:String = ExternalInterface.call("initFormAttach");				
								
				trace("결재 요청합니다. (" + reqProxy.content.length + ") " + reqProxy.content);
			}
			else {
				hideHTML();
				CommonAlert.showMessage("CommonHR", "최종 결재자를 지정하지 않았습니다.", null, "확인", null, showHTML);
			}
		}
		
		private function extraInfo():String
		{
			var info:XML = <Approval>
							<ipaddress/>
							</Approval>;
							
			info.ipaddress = ExternalInterface.call("myIP") as String;
			trace(info.toString());
			return info.toString();
		}
		
		private function showHTML():void
		{
			view.htmlArea.visible = true;
		}
		
		private function hideHTML():void
		{
			view.htmlArea.visible = false;
		}
		private function printApproval(e:Event):void
		{ 
			
			//ExternalCommand.popUpWindow(600, 400, "ehr/PrintApproval.jsp");
			var CrPattern1:RegExp = /\r/g;
			var CrPattern2:RegExp = /\r\n/g;
			var CrPattern3:RegExp = /\x22/g; 
			
			/* 
			var param:Object = new Object;
			param["AppLine"] = new Object;
			param["AppLine"].writer = view.myInfo.ENAME;
			param["AppLine"].reviewer1 = view.reviewer1.ENAME;
			param["AppLine"].reviewer2 = view.reviewer2.ENAME;
			param["AppLine"].reviewer3 = view.reviewer3.ENAME;
			param["AppLine"].responsible = view.responsible.ENAME;
			
			param["AppDate"] = new Object;
			param["AppDate"].writer = "";
			param["AppDate"].reviewer1 = "";
			param["AppDate"].reviewer2 = "";
			param["AppDate"].reviewer3 = "";
			param["AppDate"].responsible = "";
			param["title"] = view.approvalTitle;

			var CoCode:String = '';
			if(Variables.company == 'NOS') {
				CoCode = 'ONS';
			} else if(Variables.company == 'STC') {
				CoCode = 'TOP';
			} else if(Variables.company == 'SAC') {
				CoCode = 'ACE';
			}
			
			param["CoCode"] = CoCode;					// 회사코드
			param["HgCode"] = Variables.myKostl;			// 부서코드  myOrgCode ... Variables.myKostl
			param["HgName"] = Variables.myOrg;			// 부서이름
			param["UserId"] = Variables.myPernr;		// 사용자 아이디
			param["UserName"] = Variables.myName;		// 사용자 이름
			param["Sid"] 	= Variables.mySid;			// 서버 이름
			param["KeyWord"] = '';						// 필수 항목 체크를 위한 값 ... 현재 테스트 용			
			param["SlipdocKey"] = reqProxy.key;			// 결재 고유 키. 
			param["ConnKey"] = '';						// 조회시 키.
			var content:String = view.content.replace(CrPattern2, " ");
			ExternalInterface.call("execPopUpWindow", content.replace(CrPattern1, "<br>"), param);
			
			 */
			
			
			var param:URLVariables = new URLVariables();
			param["ctitle"] = view.approvalTitle;
			param["writer"] = view.myInfo.ENAME;
						
			param["AppLine"] = new Object;
			
			param["reviewer1"] = view.reviewer1.ENAME;
			param["reviewer2"] = view.reviewer2.ENAME;
			param["reviewer3"] = view.reviewer3.ENAME;
			param["responsible"] = view.responsible.ENAME;
			
			param["date1"] = "";
			param["date2"] = "";
			param["date3"] = "";
			param["date4"] = "";
			param["date5"] = "";
			
			
			var CoCode:String = '';
			if(Variables.company == 'NOS') {
				CoCode = 'ONS';
			} else if(Variables.company == 'STC') {
				CoCode = 'TOP';
			} else if(Variables.company == 'SAC') {
				CoCode = 'ACE';
			}
			 
			param["CoCode"] = CoCode;					// 회사코드
			param["HgCode"] = Variables.myKostl;			// 부서코드  myOrgCode ... Variables.myKostl
			param["HgName"] = Variables.myOrg;			// 부서이름
			param["UserId"] = Variables.myPernr;		// 사용자 아이디
			param["UserName"] = Variables.myName;		// 사용자 이름
			param["Sid"] 	= Variables.mySid;			// 서버 이름
			param["KeyWord"] = '';						// 필수 항목 체크를 위한 값 ... 현재 테스트 용			
			param["SlipdocKey"] = "nosTemp_silver";			// 결재 고유 키. 
			param["ConnKey"] = '';						// 조회시 키.
			
			
			
			var content:String = view.content.replace(CrPattern2, " ");
			content = content.replace(CrPattern1, "<br>");
			content = content.replace(CrPattern3, "'");
			param["content"] =  content;
			
        	var request:URLRequest = new URLRequest("PrintApproval.jsp");
        	request.method = URLRequestMethod.POST;
        	request.data  = param;
   			navigateToURL(request, "_blank");
		}
		
		// 전자결재 폼요청시
		private function printApprovalSend(e:Event):void
		{ 
			if(StringUtil.NVL(view.responsible.WPERNR) == "") {
				var alt:Alert = Alert.show('결재선 지정 후 폼전송 진행하시기 바랍니다.');
				alt.validateNow(); 
				alt.move(alt.x, 150);	
				return;
			}
			//ExternalCommand.popUpWindow(600, 400, "ehr/PrintApproval.jsp");
			var CrPattern1:RegExp = /\r/g;
			var CrPattern2:RegExp = /\r\n/g;
			var param:Object = new Object;
			param["AppLine"] = new Object;
			param["AppLine"].writer = view.myInfo.ENAME;
			param["AppLine"].reviewer1 = view.reviewer1.ENAME;
			param["AppLine"].reviewer2 = view.reviewer2.ENAME;
			param["AppLine"].reviewer3 = view.reviewer3.ENAME;
			param["AppLine"].responsible = view.responsible.ENAME;
			
			param["AppDate"] = new Object;
			param["AppDate"].writer = "";
			param["AppDate"].reviewer1 = "";
			param["AppDate"].reviewer2 = "";
			param["AppDate"].reviewer3 = "";
			param["AppDate"].responsible = "";
			param["title"] = view.approvalTitle;

			var CoCode:String = '';
			if(Variables.company == 'NOS') {
				CoCode = 'ONS';
			} else if(Variables.company == 'STC') {
				CoCode = 'TOP';
			} else if(Variables.company == 'SAC') {
				CoCode = 'ACE';
			}
			
			param["CoCode"] = CoCode;					// 회사코드
			param["HgCode"] = Variables.myKostl;			// 부서코드  myOrgCode ... Variables.myKostl
			param["HgName"] = Variables.myOrg;			// 부서이름
			param["UserId"] = Variables.myPernr;		// 사용자 아이디
			param["UserName"] = Variables.myName;		// 사용자 이름
			param["Sid"] 	= Variables.mySid;			// 서버 이름
			param["KeyWord"] = '';						// 필수 항목 체크를 위한 값 ... 현재 테스트 용			
			param["SlipdocKey"] = reqProxy.key;			// 결재 고유 키. 
			param["ConnKey"] = '';						// 조회시 키.
			//Alert.show('reqProxy.key : ' + reqProxy.key);
			//ExternalInterface.call("execPopUpWindow", view.content, param);
			var content:String = view.content.replace(CrPattern2, " ");
			ExternalInterface.call("execPopUpWindow", content.replace(CrPattern1, "<br>"), param);
		}		
		//0512 전자결재 .. 웹페이지 연동.
		private function eacntApproval(e:Event):void 
		{
			//폼전송 사용제거 
			/* 			
			var className:String = getQualifiedClassName(reqProxy);
			var sIdx:int = className.indexOf(":");
			className = className.substring(sIdx+2, className.length);
						
			if(Variables.company == 'SAC') {
				sFormAttach = ExternalInterface.call("getFormAttach");
									
				if(className == 'DomesticApprovalProxy' || 'ForeignApprovalProxy' ) { // 시외출장
					// 결재폼전송을 먼저 해야함.
					if(sFormAttach != 'X' && view.bTRPAYC == true) {
						var alt:Alert = Alert.show('폼전송(품의서)을 먼저 하시기 바랍니다.');
						alt.validateNow(); 
						alt.move(alt.x, 150);	
						return;						
					}
				}
				else if(className == "DailyApprovalProxy" ) { //시내출장은 무조건 증빙 확인
					// 결재폼전송을 먼저 해야함.
					if(sFormAttach != 'X') {
						var alt:Alert = Alert.show('폼전송(품의서)을 먼저 하시기 바랍니다.');
						alt.validateNow(); 
						alt.move(alt.x, 150);	
						return;						
					}						
				}
			}
			 */
						
			var param:Object = new Object;
			
			var CoCode:String = '';
			if(Variables.company == 'NOS') {
				CoCode = 'ONS';
			} else if(Variables.company == 'STC') {
				CoCode = 'TOP'; 
			} else if(Variables.company == 'SAC') {
				CoCode = 'ACE';
			}		
			
			param["CoCode"] = CoCode;					// 회사코드
			param["HgCode"] = Variables.myKostl;			// 부서코드  myOrgCode ... Variables.myKostl
			param["HgName"] = Variables.myOrg;			// 부서이름
			param["UserId"] = Variables.myPernr;		// 사용자 아이디
			param["UserName"] = Variables.myName;		// 사용자 이름
			param["Sid"] 	= Variables.mySid;			// 서버 이름 
			
			param["KeyWord"] = '';						// 필수 항목 체크를 위한 값 ... 현재 테스트 용			
			param["SlipdocKey"] = reqProxy.key;			// 결재 고유 키. 
			param["ConnKey"] = '';						// 조회시 키.
			ExternalInterface.call("eaccount_PopUpWindow", param);
		}
		
				
		private function getApprovalLines():Array
		{
			var retArr:Array = new Array();
			retArr.push(view.myInfo);
			if(view.reviewer1.WPERNR!="") retArr.push(view.reviewer1);			
			if(view.reviewer2.WPERNR!="") retArr.push(view.reviewer2);			
			if(view.reviewer3.WPERNR!="") retArr.push(view.reviewer3);			
			if(view.responsible.WPERNR!="") retArr.push(view.responsible);			
			return retArr;
		}
		
		private function onChangeAppLine(event:Event):void
		{
			if(view.selectedLevel== "00") {
				execApprovalLine();
			}
			else {
				var mediator:MemberSelectorMediator = facade.retrieveMediator(MemberSelectorMediator.NAME) as MemberSelectorMediator;
				if(mediator==null) {
					mediator = new MemberSelectorMediator();
					facade.registerMediator(mediator);
				}
				mediator.exec(view);
				view.htmlArea.visible = false;
			}
			/* 
			var mediator:MemberSelectorMediator = facade.retrieveMediator(MemberSelectorMediator.NAME) as MemberSelectorMediator;
			if(mediator==null) {
				mediator = new MemberSelectorMediator();
				facade.registerMediator(mediator);
			}
			mediator.exec(view);
			view.htmlArea.visible = false;
			*/
		}
		
		
		private function onDelAttachFile(e:Event):void
		{
			view.fileName = "";
		}
		
		private function onAddAttachFile(e:Event):void
		{
			var proxy:AttachFileProxy = getFileProxy();
			proxy.browse();
		}
		 
		private function onSelectedFile(proxy:AttachFileProxy):void
		{
			view.fileName = proxy.fileName;
		}
		
		private function getFileProxy():AttachFileProxy
		{
			var proxy:AttachFileProxy = facade.retrieveProxy(AttachFileProxy.NAME) as AttachFileProxy;
			if(proxy == null) {
				proxy = new AttachFileProxy;
				facade.registerProxy(proxy);
			}
			return proxy;
		}
		
		private function setAppLine(line:ApprovalLineVO):void
		{
			switch(line.GWARELEV) {
				case "01":
					view.myInfo = line;
					break;
				case "02":
					view.reviewer1 = line;
					break;
				case "03":
					view.reviewer2 = line;
					break;
				case "04":
					view.reviewer3 = line;
					break;
				case "09":
					view.responsible = line;
					break;
			}
		}

		private function clearAppLine():void 
		{
			view.reviewer1 = new ApprovalLineVO;	
			view.reviewer2 = new ApprovalLineVO;	
			view.reviewer3 = new ApprovalLineVO;	
			view.responsible = new ApprovalLineVO;	
		}

		private var appLineMediator:AppLineMediator = null;
		private function execApprovalLine():void
		{
			view.htmlArea.visible = false;
			if(appLineMediator==null) {
				appLineMediator = new AppLineMediator();
				facade.registerMediator(appLineMediator);
			}
			appLineMediator.execView(view, getAppLineList());
		}
		
		private function getAppLineList():ArrayCollection
		{
			var arr:ArrayCollection = new ArrayCollection();
			var vo:ApprovalLineVO;
			
			vo = new ApprovalLineVO();
			vo.GWARELEV = "01";
			vo.labelName = "기안";
			vo.WPERNR = view.myInfo.WPERNR;
			vo.ENAME = view.myInfo.ENAME;
			vo.PLANST = view.myInfo.PLANST;
			arr.addItem(vo);
			
			vo = new ApprovalLineVO();
			vo.GWARELEV = "02";
			vo.labelName = "검토1";
			vo.WPERNR = view.reviewer1.WPERNR;
			vo.ENAME = view.reviewer1.ENAME;
			vo.PLANST = view.reviewer1.PLANST;
			arr.addItem(vo);
			
			vo = new ApprovalLineVO();
			vo.GWARELEV = "03";
			vo.labelName = "검토2";
			vo.WPERNR = view.reviewer2.WPERNR;
			vo.ENAME = view.reviewer2.ENAME;
			vo.PLANST = view.reviewer2.PLANST;
			arr.addItem(vo);
			
			vo = new ApprovalLineVO();
			vo.GWARELEV = "04";
			vo.labelName = "검토3";
			vo.WPERNR = view.reviewer3.WPERNR;
			vo.ENAME = view.reviewer3.ENAME;
			vo.PLANST = view.reviewer3.PLANST;
			arr.addItem(vo);
			
			vo = new ApprovalLineVO();
			vo.GWARELEV = "09";
			vo.labelName = "승인";
			vo.WPERNR = view.responsible.WPERNR;
			vo.ENAME = view.responsible.ENAME;
			vo.PLANST = view.responsible.PLANST;
			arr.addItem(vo);
			
			return arr;
			
		}
		
		private function setAppLineList(src:ArrayCollection):void
		{
			for each(var vo:ApprovalLineVO in src) {
				switch(vo.GWARELEV) {
					case "02":
						view.reviewer1 = vo;
						break;
					case "03":
						view.reviewer2 = vo;
						break;
					case "04":
						view.reviewer3 = vo;
						break;
					case "09":
						view.responsible = vo;
						break;
				}
			}			
		}
		///////////////////////////////////////////////////////////////////////////////////////////////////
		//
		//	Utility Functions
		//
		///////////////////////////////////////////////////////////////////////////////////////////////////
        private function get view():RequestApproval
        {
            return viewComponent as RequestApproval;
        }
	}
}